package com.guigu.springcloud.service;

import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.UUID;


@Component
// 将消息推送到通道中
@EnableBinding(IMessageProvider.class)
public class MessageProviderImpl {

    @Resource
    private IMessageProvider messageProvider;

    public String send() {
        // 将通道和数据源绑定
        String message = UUID.randomUUID().toString();
        messageProvider.output().send(MessageBuilder.withPayload(message).build());
        System.out.println("----serial: " + message);
        return message;
    }
}
